package cn.hotel.service.impl;

import cn.hotel.entity.Worker;
import cn.hotel.mapper.WorkerMapper;
import cn.hotel.service.WorkerService;
import cn.hotel.utils.MD5Utils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import javax.annotation.Resource;

@Service
public class WorkerServiceImpl implements WorkerService {

    @Resource
    private WorkerMapper workerMapper;

    @Override
    public Worker queryWorkerByUsernameAndPassword(String username, String password) {
        password = MD5Utils.MD5Encode(password);
        Worker worker = workerMapper.queryWorkerByUserAndPass(username, password);
        return worker;
    }
    @Override
    public Worker queryUserByUserAndPass(String username, String password) {
        //对密码进行加密
        password = MD5Utils.MD5Encode(password);
        Worker worker = workerMapper.queryUserByUserAndPass(username, password);
        return worker;
    }

    @Override
    public List<Worker> queryAllWorkers() {
        return workerMapper.getAllWorkers();
    }

    @Override
    public PageInfo<Worker> queryWorkerList(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        PageInfo<Worker> pageInfo = new PageInfo<>(workerMapper.getAllWorkers());
        return pageInfo;
    }

    @Override
    public void insertWorkerInfo(Worker worker) {
        workerMapper.insertWorkerInfo(worker);
    }

    @Override
    public Worker queryWorkerInfo(int workerId) {
        return workerMapper.queryWorkerInfo(workerId);
    }

//    @Override
//    public void updateWorkerInfo(Worker worker) {
//        workerMapper.updateWorkerInfo(worker);
//    }

    @Override
    public void deleteWorkerInfo(int workerId) {
        workerMapper.deleteWorkerInfo(workerId);
    }

    @Override
    public int updateWorker(Worker worker) {
        int i = workerMapper.updateWorker(worker);
        return i;
    }
}
